package com.example.hfiveandaplication.utils;

public class StringUtils {

    public static boolean isEmpty(String str) {
        return str == null || str.trim().length() == 0;
    }

    public static String getDotMoneyStr( String money) {
        char[] chars = money.toCharArray();
        if (chars.length > 3) {

            int dotNum = chars.length / 3;
            if (chars.length % 3 == 0) {
                dotNum = dotNum - 1;
            }

            char[] containerChar = new char[chars.length + dotNum];

            for (int countTime = 0, targetIndex = chars.length + dotNum - 1, i = chars.length - 1; i >= 0; i--) {

                countTime++;

                containerChar[targetIndex] = chars[i];
                if (countTime % 3 == 0) {

                    if (targetIndex - 1 > 0) {
                        containerChar[targetIndex - 1] = '.';
                        targetIndex--;
                        targetIndex--;
                    } else {
                        break;
                    }
                } else {
                    targetIndex--;
                }
            }

            return new String(containerChar);
        } else {
            return money;
        }

    }

    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }

    public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for (int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }


}
